package com.gs.common.util

import android.app.Dialog
import android.content.Context
import android.content.res.Resources
import android.graphics.Bitmap
import android.widget.ImageView
import com.google.zxing.BarcodeFormat
import com.google.zxing.qrcode.QRCodeWriter
import com.gs.common.R

object QRCodeUtil {

    fun generateQRCode(resources: Resources,url: String, width: Int, height: Int): Bitmap {
        val qrCodeWriter = QRCodeWriter()
        val bitMatrix = qrCodeWriter.encode(url, BarcodeFormat.QR_CODE, width, height)
        val qrCodeBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565)
        for (x in 0 until width) {
            for (y in 0 until height) {
                qrCodeBitmap.setPixel(x, y,
                    if (bitMatrix.get(x, y))
                        resources.getColor(com.gs.common.R.color.black)
                    else resources.getColor(com.gs.common.R.color.white)
                )
            }
        }
        return qrCodeBitmap
    }
}